package com.yaozheng.vocationaltraining.adapter;

import net.sf.json.JSONArray;

import com.yaozheng.vocationaltraining.utils.TypeUtils;
import com.yaozheng.vocationaltraining.view.ItemQuestionView;
import com.yaozheng.vocationaltraining.view.ItemQuestionView_;
import com.yaozheng.vocationaltraining.view.paper.ItemQuestionListView;
import com.yaozheng.vocationaltraining.view.paper.ItemQuestionListView_;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

public class HomeAnswerTaskAdapter extends PagerAdapter {

    private Context context;

    private JSONArray dataList;

    public HomeAnswerTaskAdapter(Context context, JSONArray dataList) {
        super();
        this.context = context;
        this.dataList = dataList;
    }

    public void setDataList(JSONArray dataList) {
        this.dataList = dataList;
    }

    public JSONArray getDataList() {
        return dataList;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) { // 这个方法用来实例化页卡
//		ItemQuestionView itemQuestionView = ItemQuestionView_.build(context);
        ItemQuestionListView itemQuestionListView = ItemQuestionListView_.build(context);
        itemQuestionListView.loadData(position,
                TypeUtils.getJsonObject(dataList, position));
        container.addView(itemQuestionListView);// 添加页卡
        return itemQuestionListView;
    }

    @Override
    public int getCount() {
        return TypeUtils.getJsonArraySize(dataList);
    }
}
